
# 写程序，输入一个百度的查询关键字如 "美女"
# 将返回的网页存入文件 '美女.html'

import requests

keyword = input('请输入搜索的关键字：')
# https://www.baidu.com/s?wd=%E7%BE%8E%E5%A5%B3
url = 'https://www.baidu.com/s'
# 把浏览器，伪装成为浏览器
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36'
}
params = {
    'wd': keyword
}
resp = requests.get(url,
    headers=headers,
    params=params
)
with open(keyword+'.html', 'wb') as fw:
    fw.write(resp.content)

